﻿using System.Net;
using System.Net.Http;
using System.Web.Http.Filters;
using SelfMadeMillioniare.API.Helpers;
using SelfMadeMillioniare.API.TransportObjects;

namespace SelfMadeMillioniare.API.Filters
{
    public class MyCustomExceptionFilter : ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext context)
        {
            var exceptionType = context.Exception.GetType();

            Response response = ResponseHelper.GetResponse();

            response.AddValidateError(Response.Message, HttpStatusCode.InternalServerError.ToString());

            context.Response = context.Request.CreateResponse(HttpStatusCode.InternalServerError);
        }
    }
}